<?php
registerTable("table_application_nodeArray", new table_application_nodeArray());

class table_application_nodeArray extends Database
{
    public function __construct()
    {
        parent::__construct("nodearray");
    }

    public function pushData($gatewayID, $nodeName, $data)
    {
        // if ($this->contains($gatewayID, $nodeName)) {
        //     parent::update(array("data" => $data), "`location`=$gatewayID AND `requestname`='$requestname'");
        //     return;
        // }
        parent::insert(array(
            COLUMN_Gateway => $data[COLUMN_Gateway], COLUMN_NodeName => $data[COLUMN_NodeName],
            COLUMN_NodeState => $data[COLUMN_NodeState], COLUMN_SensorNum => $data[COLUMN_SensorNum],
            COLUMN_SensorTypeArray => $data[COLUMN_SensorTypeArray]
        ), null);
    }

    public function contains($location, $requestname)
    {
        return $this->count_something("`location`=$location AND `requestname`='$requestname'") == 1;
    }

    public function fetch_by_location_and_requestname($requestname, $location)
    {
        return $this->fetch_assoc("`location`=$location AND `requestname`='$requestname'");
    }
}
